/*
https://leetcode-cn.com/problems/stamping-the-sequence/solution/chuo-yin-xu-lie-by-leetcode/
 */
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution936 {
    public int[] movesToStamp(String stamp, String target) {
        List<Integer> ans=new ArrayList<>();
        char[] cur=target.toCharArray();
        while (true){
            boolean ff=false;
            for (int i=0;i<target.length()-stamp.length()+1;i++){
                boolean flag=true;
                for (int j=i;j<i+stamp.length();j++){
                    if (cur[j] != '?') {
                        flag = false;
                        break;
                    }
                }
                if (flag){
                    continue;
                }
                for (int j=0;j<stamp.length();j++){
                    if (stamp.charAt(j)!=cur[i+j] && cur[i+j]!='?'){
                        flag=true;
                        break;
                    }
                }
                if (!flag){
                    ff=true;
                    ans.add(i);
                    for (int j=i;j<i+stamp.length();j++){
                        cur[j]='?';
                    }
                    for (int j=0;j<cur.length;j++){
                        if (cur[j]!='?'){
                            flag=true;
                            break;
                        }
                    }
                    if (!flag){
                        int[] f=new int[ans.size()];
                        for (int j=0;j<ans.size();j++){
                            f[j]=ans.get(ans.size()-j-1);
                        }
                        return f;
                    }
                }
            }
            if (!ff){
                return new int[0];
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution936().movesToStamp("abca", "aabcaca")));
    }
}
